package cn.eleven.controller;

import cn.eleven.common.Result;
import cn.eleven.entity.Chat;
import cn.eleven.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin("*")
@RestController
@RequestMapping("/chat")
public class ChatController {

    @Autowired
    private ChatService chatService;

    @PostMapping("/send")
    public Result sendChatMessage(@RequestBody Chat chat) {
        boolean success = chatService.sendChatMessage(chat);
        if (success) {
            return Result.success();
        } else {
            return Result.error("发送失败");
        }
    }

    @GetMapping("/history")
    public Result getChatHistory() {
        List<Chat> history = chatService.getChatHistory();
        return Result.success(history);
    }
}